//
//  ImagePickerViewController.m
//  模块整理
//
//  Created by YH on 2018/4/23.
//  Copyright © 2018年 YH. All rights reserved.
//

#import "ImagePickerViewController.h"
#import "ImagePickerCollectionViewCell.h"

static NSString *CellWithReuseIdentifier =  @"ImagePickerCollectionViewCell";

@interface ImagePickerViewController ()<UICollectionViewDelegate,
                                        UICollectionViewDataSource>

@property (weak, nonatomic) IBOutlet UICollectionView   *collectionView;

@property (nonatomic, strong) NSMutableArray            *dataArray;

@end

@implementation ImagePickerViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.collectionView registerNib:[UINib nibWithNibName:@"ImagePickerCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:CellWithReuseIdentifier];
}

#pragma mark  Action

- (IBAction)responseToCancelButton:(id)sender
{
    [self dismissViewController];
}

- (IBAction)responseToAlbumButton:(id)sender
{

}

#pragma mark UICollectionViewDelegate UICollectionViewDataSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 50;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ImagePickerCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellWithReuseIdentifier forIndexPath:indexPath];
    cell.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:arc4random() % 256 / 255.0];
        return cell;
}

#pragma mark  初始化数组

-(NSMutableArray *)dataArray
{
    if (nil == _dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}

#pragma mark  自定义方法

- (void)dismissViewController
{
    CATransition *transition = [CATransition animation];
    transition.duration = 1.f;
    transition.type = kCATransitionReveal;
    transition.subtype = kCATransitionFromBottom;
    [self.view.superview.layer addAnimation:transition forKey:nil];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self dismissViewController];
}

@end
